home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Where Can I Find Standard C Library S
- Date: Fri, 09 Feb 96 01:45:29 GMT
- Organization: none
- Message-ID: <823830329snz@genesis.demon.co.uk>
- References: <4fb8mf$ouo@spanky.pls.ov.com> <4fb90l$ouo@spanky.pls.ov.com> <3119E6D9.60FD@cmt.lpr.mail.carel.fi>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <3119E6D9.60FD@cmt.lpr.mail.carel.fi>
- aril@cmt.lpr.mail.carel.fi "Ari Lukumies" writes:
-
- >Fletcher.Glenn@ov.com wrote:
- >>
- >>
- >> Whoops! for strcpy:
- >>
- >> char *strcpy(char *destination, char *source)
- >> {
- >> char *retval;
- >>
- >> retval = destination;
- >> while((*destination++ = *source++) != '\0');
- >> return(retval);
- >> }
- >> Fletcher.Glenn@ov.com
- >
- >... And you wonder why printf("%s\n", strcpy(tmp, "thingyam")); may not give
- > correct
- >results using your strcpy version... Try this for size:
- >
- > char *strcpy(char *destination, char *source)
- > {
- > char *retval = destination;
- >
- > do
- > *destination = *source++;
- > while (*destination++ != '\0');
- > return retval;
- > }
- >
- >This will also copy the nul-terminator. :)
-
- If you look more closely you'll see that your version has exactly the
- same behaviour as Glenn's, which correctly copies the null character
- terminator. However both should be:
-
- char *strcpy(char *destination, const char *source)
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-